Mule : Axis Web Services and Mule
This page last changed on May 31, 2006 by tcarlson.
Axis integrates with Mule meaning you can expose Mule components as Axis services and invoke Axis Services from mule. To expose a Mule component as an Axis service all you have to do is set the components receive endpoint to An Axis URL, i.e. <mule-descriptor name="echoService" inboundEndpoint="axis:http://localhost:81/services" implementation="org.mule.components.simple.EchoComponent"> </mule-descriptor> When Mule starts, the service will be available on http://localhost:81/services/echoService. The Echo component class implements the EchoService interface that has a single method called echo that accepts a single parameter string. Invoking Web ServicesThere are two ways of invoking webservices from Mule.
Each method is described in detail in the following sections. Invoking Services with the MuleClientTo invoke Echo Service using the Mule Client, use the following - TestEchoService.java public static void main(String[] args) { MuleClient client = new MuleClient(); UMOMessage result = client.send ("axis:http://localhost:81/services/echoService?method=echo", "Hello!", null); System.out.println("Message Echoed is: " + result.getPayload()); client.close(); } Invoking Web Services from a ComponentTo invoke the Echo Service from a component you need to add an outbound endpoint to your component descriptor. The example shown below is a component that receives an event on vm://test.component, does some work on the event and then invokes or echo service. <mule-descriptor name="test" implementation="com.foo.TestComponent"> <inbound-router> <endpoint address="vm://test.component" synchronous="true"/> <inbound-router> <outbound-router> <router className="org.mule.routing.outbound.OutboundPassThroughRouter"> <endpoint address=" axis:http://localhost:81/services/echoService?method=echo"/> </router> </outbound-router> </mule-descriptor> The org.foo.TestComponent looks like - org.foo.TestComponent public class TestComponent implements Callable { public Object onCall(UMOEventContext context) throws Exception { Object payload = context.getMessage().getPayload(); //Do some work on the payload and return a string that will be //used by the outbound endpoint to invoke the echo service //... return payload.toString(); } } If the Web service you are invoking takes more than one parameter, just return an array of parameters in your component. When an event is published vm://test.component the onCall method will be called with the current event. After the onCall method executes, Mule will invoke the outbound endpoint for TestComponent with what is returned from the onCall method call. Note that the vm://test.component endpoint has a parameter synchronous=true. This tells Mule to invoke requests from that endpoint in a single thread, making it a request/response style request. Thus the result of invoking the Echo Service (by invoking Test Component) will be returned to the callee who dispatched the event on vm://test.component. When the TestEchoService is run you will see the following output - Message Echoed is: Hello!
There are a couple of things to note about this demonstration -
You will need to have the Axis jar and associated jars on your classpath, these ship with the Mule distribution.
Axis without a Servlet ContainerUsing Axis with Mule means there is no need for a separate servlet container. When an axis endpoint such as 'axis:http://localhost:81/services' is declared, mule does a couple of things -
Most web services are a lot more complex than the first example so the following sections will tell you how to configure the Axis instance and your services in more detail. Configuring the Axis ServerIn the previous example, a default Axis connector is created when the axis endpoint is processed by Mule. The Axis connector uses a default server configuration file called mule-server-config.wsdd. You can override this configuration by setting the serverConfig on the connector. This will allow you add additional Handlers, global configuration, etc. <connector name="axisConnector" className="org.mule.providers.soap.axis.AxisConnector"> <properties> <property name="serverConfig" value="./axis/axis-server-config.wsdd"/> </properties> </connector> If you use a custom server configuration remember to add the following handlers in the global configuration - <requestFlow> <handler type="java:org.mule.providers.soap.axis.extensions.MuleSoapHeadersHandler"/> </requestFlow> <responseFlow> <handler type="java:org.mule.providers.soap.axis.extensions.MuleSoapHeadersHandler"/> </responseFlow> If you are configuring Mule from a container such as Spring, you can set the Axis server as a bean property on the connector and the serverConfig property is ignored. You can list the Axis services in the same way you list services when Axis is hosted in a servlet container. To list services simply point your browser at the host and port of the axis endpoint - http://localhost:81/ To view Axis version information go to - http://localhost:81/Version?method=getVersion To view the WSDL for the service go to- http://localhost:81/Version?wsdl Note that the Axis JWS feature is not supported by Mule. Soap over Other Transports For more information about customising Axis behaviour, Naming parameters, Message style options and more see Configuring Axis. |
Document generated by Confluence on Nov 27, 2006 10:27 |